#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
char pre[1005],in[1005],post[1005];
void pos(int xl,int xr,int hl,int hr){
int i=0;
if(xl>xr)
    return;
char ch=pre[xl];
while(ch!=in[i])
    i++;
int lenl=i-hl;
int lenr=hr-i;
pos(xl+1,xl+lenl,hl,i-1);
pos(xl+lenl+1,xr,i+1,hr);
cout<<ch;

}


int main(){
        cin>>pre>>in;
        int n=strlen(pre);
        pos(0,n-1,0,n-1);

        return 0;
}
